package com.chance.cc.crawler.development.bootstrap.taobao;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterInfo;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerDataType.article;
import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerDataType.comment;

/**
 * @author bx
 * @date 2020/11/18 0018 18:13
 */
public class TaobaoSearchStart {

    private static final String searchUrl = "https://s.taobao.com/search?ajax=true&callback=jsonp764&q=%s" +
            "&ie=utf8&js=1&stats_click=search_radio_all%%3A1&p4ppushleft=1%%2C48";

    public static final String domainId = "taobao";

    public static void main(String[] args) throws UnsupportedEncodingException {

        String keyword = URLEncoder.encode("耐克", "utf-8");

        FilterInfo countFilterInfo = new FilterInfo();
        countFilterInfo.setFilter(CrawlerEnum.CrawlerRecordFilter.count);
        countFilterInfo.setCountTotalNum(100);
        countFilterInfo.setCurCount(0);

        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domainId, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(String.format(searchUrl,keyword))
                .httpHead("referer","https://s.taobao.com/")
                .httpHead("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36")
                .httpHead("cookie","_samesite_flag_=true; cookie2=1b657d46efd4104d1dfe089dc4a1835c; t=6952f998ef3b907ad51292a7cbf8cb4d; _tb_token_=335abab33b9ea; cna=EQk9GPo4tywCATohFCIv0irN; xlly_s=1; lgc=%5Cu7CFB%5Cu8FD8%5Cu7B97%5Cu4E0D; dnk=%5Cu7CFB%5Cu8FD8%5Cu7B97%5Cu4E0D; tracknick=%5Cu7CFB%5Cu8FD8%5Cu7B97%5Cu4E0D; _cc_=UIHiLt3xSw%3D%3D; sgcookie=E1002dnfUSdAdGIP6yADLAzWStxjhLkgB0F12nqltpl1wQb5WvmUK9C%2FBqBYFnfvuCpaeJb9e59jRdwPZWyrAKQu7A%3D%3D; uc3=nk2=rL9CGfhTA0w%3D&lg2=UIHiLt3xD8xYTw%3D%3D&vt3=F8dCufwsARmN2xd%2B3hg%3D&id2=UUkJYAV8aFQ8rg%3D%3D; csg=72fcf25b; skt=feb5b85bc8e9665d; existShop=MTYwNTc3MDE4Mw%3D%3D; uc4=nk4=0%40rpHMnVi0ocDUvwAd92lMKLQEmg%3D%3D&id4=0%40U2uFVlzHXCqDYyRTGjsxkgJMFzGo; mt=ci=0_1; thw=cn; v=0; _m_h5_tk=77c878ea553015b36a760c4109aab104_1605777392010; _m_h5_tk_enc=0239c12254ea1dfbcf9f98972b119114; enc=oIjV9uj7Tq8%2B9NhSiPMLibYaG9mOrHlUetl6NApTTB9pnppJIqD6ED3KAGsPPEdkdbBl9nFihtJJowHXgm7n4w%3D%3D; alitrackid=www.taobao.com; lastalitrackid=www.taobao.com; hng=CN%7Czh-CN%7CCNY%7C156; uc1=cookie16=W5iHLLyFPlMGbLDwA%2BdvAGZqLg%3D%3D&existShop=false&cookie21=URm48syIYB3rzvI4CflX&cookie14=Uoe0aDvbLJSqdQ%3D%3D&pas=0; JSESSIONID=A3EE5C29ED5C7CE2FD2D6002C6B84766; x5sec=7b227365617263686170703b32223a226266353434363536356131363639623737396332343132353064653937643437434f336132503046454a62653959727171764f564f526f4d4d6a45334e6a41304e7a41304f447378227d; tfstk=cnBPBuGT48ey-dvQ6L9ENrF2pGKRakXhC7KpZ6zTnWf3ODRk7sfZJnYbUaQeW-Al.; l=eBOxt66gO3-sj6UABO5Churza779WIdbz1PzaNbMiInca1VR1dfd5NQVzOYDRdtjgtfvnetr09hQ7RH67dadg2HvCbKrCyCowY96-; isg=BJKSTWI0GZvVaWXnl8XS9Ngy41h0o5Y9lxlgOFzqTcWubzBpRDAATafJ38vTGA7V")
                .releaseTime(System.currentTimeMillis())
                .needWashed(true)
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domainId))
                .turnPageFilterInfo(countFilterInfo)
                .build();


        DevCrawlerController.builder()
                .triggerInfo(domainId,domainId,System.currentTimeMillis(),domainId)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domainId))
                .consoleResultPipeline()
                .fileResultPipeline("D:\\chance\\log\\tets.log",true)
                .requestRecord(requestRecord)
                .build().start();
    }
}
